/*
 * @Description: 路由参数配置
 * @Author: CrowBlock81192
 * @Date: 2024-03-22 22:36:38
 */

import type { RouteRecordRaw } from 'vue-router';

// 获取modules中的路由规则
// https://cn.vitejs.dev/guide/features.html#glob-import
const modules: Record<string, { default: RouteRecordRaw | RouteRecordRaw[] }> = import.meta.glob('./modules/**/*.ts', { eager: true });

// modules routes
const routes: RouteRecordRaw[] = [];

Object.keys(modules).forEach((key) => {
	const modulesRoutes = modules[key].default || {};

	let modRoutesList: RouteRecordRaw[] = [];
	if (Array.isArray(modulesRoutes)) {
		modRoutesList = [...modulesRoutes];
	} else {
		modRoutesList = [modulesRoutes];
	}

	routes.push(...modRoutesList);
});

// 根目录
const rootRoute: RouteRecordRaw = {
	path: '/',
	name: 'root',
	redirect: '/home',
};

// 首页
const HomePage: RouteRecordRaw = {
	path: '/home',
	name: 'home',
	component: () => import('@/views/home/index.vue'),
};

// 404页面
const notFoundPage: RouteRecordRaw = {
	path: '/:pathMatch(.*)*',
	name: '404',
	component: () => import('@/views/error-page/404.vue'),
};

const allRoutes: RouteRecordRaw[] = [rootRoute, HomePage, ...routes, notFoundPage];

export default allRoutes;
